package com.brainardphotography.blog.web;

import javax.servlet.http.HttpServletRequest;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;
import com.google.inject.Inject;
import com.google.sitebricks.rendering.EmbedAs;

@EmbedAs("Footer")
public class Footer extends BasePage {
	private static final long serialVersionUID = 2550611902145184335L;
	
	private UserService users;
	private User user;
	private HttpServletRequest request;

	@Inject
	public Footer(HttpServletRequest request) {
		this.users = UserServiceFactory.getUserService();
		this.request = request;

		this.user = users.getCurrentUser();
	}

	public User getUser() {
		return user;
	}

	public boolean getLoggedIn() {
		return users.isUserLoggedIn();
	}

	public boolean getAdmin() {
		if(getLoggedIn())
			return "dorkymusician@gmail.com".equals(this.user.getEmail().toLowerCase())
					|| this.users.isUserAdmin();
		
		return false;
	}

	public String getLoginUrl() {
		return this.users.createLoginURL(request.getRequestURI());
	}

	public String getLogoutUrl() {
		return this.users.createLogoutURL(request.getRequestURI());
	}
}
